<?php
/**
 * Created by PhpStorm.
 * User: jingshou
 * Date: 2017/9/17
 * Time: 23:57
 */

namespace app\mobile\model;

use think\Model;
use think\Session;

class JieModel extends Model
{
    protected $table = 'tp_jie';

    public function getMaxPicture1ThumbAttr()
    {
        return rep_split($this->maxPicture1);
    }

    public function getMaxPicture2ThumbAttr()
    {
        return rep_split($this->maxPicture2);
    }

    public function getMaxPicture3ThumbAttr()
    {
        return rep_split($this->maxPicture3);
    }

    public function getList()
    {
        return self::where(['language' => Cookie::get('language'), 'state' => 1, 'isIndex' => 1])
            ->order('sort asc')
            ->limit(8)
            ->select();
    }

    public function getListAll($row = 6)
    {
        return self::find()
            ->where(['language' => Cookie::get('language'), 'state' => 1, 'isNav' => 1])
            ->order('sort asc')
            ->paginate($row);
    }

    public function getInfo($id)
    {
        return self::where(['language' => Cookie::get('language'), 'id' => $id])->order('id asc')->limit(1)->find();
    }

    public function getOne($condition, $order = 'id asc')
    {
        $condition = array_merge(['language' => Cookie::get('language'), 'state' => 1], $condition);
        return self::where($condition)->order($order)->find();
    }

    public function getNavList()
    {
        return [
            '1' => ['type' => 'meal', 'label' => '餐饮行业解决方案'],
            '2' => ['type' => 'online', 'label' => '电商综合体解决方案'],
            '3' => ['type' => 'chain', 'label' => '连锁店电商解决方案'],
            '4' => ['type' => 'branch', 'label' => '全网分销系统解决方案'],
        ];
    }

    public function getJieType($id)
    {
        $list = $this->getNavList();
        return empty($list[$id]) ? 'meal' : $list[$id]['type'];
    }
}